
#include "stdafx.h"
#include "displaymediator.h"
#include "displaytabctrl.h"
#include "displaymdi.h"
#include "displayfrm.h"

CDisplayMediator::CDisplayMediator()
: m_pTabCtrl(NULL)
, m_pDisplayMdi(NULL)
{
}

void CDisplayMediator::Register(CDisplayTabCtrl* pTabCtrl)
{
	ATLASSERT(pTabCtrl);

	m_pTabCtrl = pTabCtrl;
	m_pTabCtrl->SetMediator(this);
}

void CDisplayMediator::Register(CDisplayMdi* pDisplayMdi)
{
	ATLASSERT(pDisplayMdi);

	m_pDisplayMdi = pDisplayMdi;
	m_pDisplayMdi->SetMediator(this);
}

void CDisplayMediator::Register(CDisplayFrame* pDisplayFrame)
{
	ATLASSERT(pDisplayFrame);

	m_pDisplayFrame = pDisplayFrame;
	m_pDisplayFrame->SetMediator(this);
}

// TabCtrl -> Mdi
void CDisplayMediator::ChangedShow(CChildFrame* pChildFrame)
{
	m_pDisplayMdi->ExecuteShowFrame(pChildFrame);
}

void CDisplayMediator::ChangedClose(CChildFrame* pChildFrame, CChildFrame* pShow)
{
	m_pDisplayMdi->ExecuteQuitView(pChildFrame, pShow);
}

// Mdi -> TabCtrl
void CDisplayMediator::ChangedAddTab(CChildFrame* pChildFrame)
{
	if (pChildFrame != NULL)
	{
		CWindowText strTitle(pChildFrame->m_hWnd);
		m_pTabCtrl->AddTab(strTitle, _T("NULL"), pChildFrame, true);
	}
}

void CDisplayMediator::ChangedDelTab(CChildFrame* pChildFrame)
{

}

void CDisplayMediator::ChangedTitle(CChildFrame* pChildFrame, LPCTSTR lpszTitle)
{
	m_pTabCtrl->SetTabTitle(lpszTitle, pChildFrame);
}

// TabCtrl -> Frame
void CDisplayMediator::ChangedQuitFrame()
{
	m_pDisplayFrame->PostMessage(WM_CLOSE);
}